package com.jkd.service.impl;

import com.jkd.mapper.StuRoomRelateMapper;
import com.jkd.model.pojo.Room;
import com.jkd.model.pojo.StuRoomRelate;
import com.jkd.service.IStuRoomRelateService;
import com.jkd.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class StuRoomRelateServiceImpl implements IStuRoomRelateService {
    @Override
    public Boolean insert(StuRoomRelate stuRoomRelate) {

        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        StuRoomRelateMapper stuRoomRelateMapper = sqlSession.getMapper(StuRoomRelateMapper.class);
       int row = stuRoomRelateMapper.insert(stuRoomRelate);
        sqlSession.commit();
       Boolean flag;
       if(row>0){
           flag = true;
       }else
       {
           flag = false;
       }
       MyBatisUtil.closeSqlSession(sqlSession);
        return flag;
    }

    @Override
    public Integer selectByStuIdAndRoomId(Integer stuId) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        StuRoomRelateMapper stuRoomRelateMapper = sqlSession.getMapper(StuRoomRelateMapper.class);
       Integer relateId = stuRoomRelateMapper.selectByStuIdAndRoomId(stuId);
       MyBatisUtil.closeSqlSession(sqlSession);
       return  relateId;
    }

    @Override
    public List<StuRoomRelate> selectByRoomId(Integer roomId) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        StuRoomRelateMapper stuRoomRelateMapper = sqlSession.getMapper(StuRoomRelateMapper.class);
        List<StuRoomRelate> list = stuRoomRelateMapper.selectByRoomId(roomId);
        MyBatisUtil.closeSqlSession(sqlSession);
        return list;
    }
}
